#include "GMActorChanges.h"
#include "Engine.h"
#include "GameState.h"
#include "NetworkedActor.h"

GMActorChanges::GMActorChanges() : m_networkActorID(-1)
{
    memset(m_translation, 0, sizeof(float)*3);
    memset(m_rotation, 0, sizeof(float)*4);
    memset(m_linearVelocity, 0, sizeof(float)*3);
    memset(m_angluarVelocity, 0, sizeof(float)*3);
}
bool GMActorChanges::Execute()
{
    NetworkedActor* na = Engine::Instance()->GetCurrentState()->FindNetworkedActor(m_networkActorID);
    if(na == NULL)
        return true;

    na->UpdateToServer(*this);
    return true;
}
void GMActorChanges::WriteToSckMsg( Networking::SockMsg* sm )
{
    sm->WriteInt(m_networkActorID);
    for(int i = 0; i < 3; ++i)
        sm->WriteFloat(m_translation[i]);
    for(int i = 0; i < 4; ++i)
        sm->WriteFloat(m_rotation[i]);
    for(int i = 0; i < 3; ++i)
        sm->WriteFloat(m_linearVelocity[i]);
    for(int i = 0; i < 3; ++i)
        sm->WriteFloat(m_angluarVelocity[i]);
}
bool GMActorChanges::ReadFromSckMsg( Networking::SockMsg* sm )
{
    if(!sm->ReadInt(&m_networkActorID))
        return false;
    for(int i = 0; i < 3; ++i)
        if(!sm->ReadFloat(&m_translation[i]))
            return false;
    for(int i = 0; i < 4; ++i)
        if(!sm->ReadFloat(&m_rotation[i]))
            return false;
    for(int i = 0; i < 3; ++i)
        if(!sm->ReadFloat(&m_linearVelocity[i]))
            return false;
    for(int i = 0; i < 3; ++i)
        if(!sm->ReadFloat(&m_angluarVelocity[i]))
            return false;
    return true;
}

